<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<style>

    body .demo-class .layui-layer-btn0 {
        border-color: #e2e2e2;
        background-color: #fff;
        color: #333;
    }
</style>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
            <div style="margin: 10px 10px 10px 10px">

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" name="search" autocomplete="off" class="layui-input soso" placeholder="可按【费用标题】搜索">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                    </div>
                </div>

            </div>
        </form>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <!--<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>-->
            <!--<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>-->
        </script>
    </div>
</div>
{include file="public/footer" /}
<script type="text/html" id="look">
    <button data-method="offset" data-type="auto" class="layui-btn lookstyle" lay-event="look">查看</button>
</script>


<script type="text/html" id="matchingType">

    {{#  if(d.status === 1){ }}
    <span style="color: #28f51d;">展示中</span>
    {{# }else if(d.status === 2){ }}
    <span style="color: #f59b28;">待展示</span>
    {{# }else if(d.status === 3){ }}
    <span style="color: #f42540;">已结束</span>
    {{#  } }}



</script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        var type = $("input[name='type']").val();


        let arr_data={
            elem: '#currentTableId',
            url: '/admin/cost/index?active=ajax',
            method: 'post',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter'],

            cols: [[
                // {type: "checkbox",},
                {field: 'title', title: '费用标题'},
                {field: 'cate_title', title: '费用类型'},
                {field: 'explain', title: '描述内容',toolbar: '#look'},
                {field: 'price', title: '金额'},
                {field: 'create_time', title: '时间'},
                // {title: '操作', toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        }
        table.render(
            arr_data
        );

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });


        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '创建消息',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/cost/saveinfo',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var id = obj.data.id;
            var explain = obj.data.explain;
            var rendor = form.render();

            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "/admin/cost/saveinfo?id="+id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else  if (obj.event === 'look') {
                //触发事件  查看内容
                var index = layer.open({
                    title:'消息内容',
                    type: 1,
                    area: ['100%','100%' ],
                    fixed: false, //不固定
                    shade:0.5,
                    shadeClose:true,
                    content:'<div align="center">'+explain+'</div>' ,
                });
            } else  if (obj.event === 'lookMember') {
                getMemberAjax('',id,'');
            } else  if (obj.event === 'delete') {
                layer.confirm('确定要删除么?', function (index) {
                    //发异步删除数据
                    $.ajax({
                        url: '/admin/notice/notice_del',
                        type: 'post',
                        dataType: 'json',
                        data: {id: id},
                        success: function (data) {
                            if (data.status) {
                                layer.msg('删除成功!', {
                                    icon: 1,
                                    time: 1000
                                });
                                obj.del();

                            }
                        },
                        error: function () {
                            layer.msg("删除失败");
                        }
                    });
                    layer.close(index);
                });

            }
        });


    });
    //用户类型  显示用户名称
    function selectMemberType(name){
        // 选择合伙人
        layer.open({
            type: 1,
            title: "用户名称",
            area: ['1000px', '630px'],
            shade: 0.5,
            maxmin: true,
            content: "     <div class=\"layui-form-item\">\n" +
                "                <label class=\"layui-form-label\" style=\"margin-left:-1px;\">用户名称</label>\n" +
                "                <div class=\"layui-input-block showuser\"  style='padding:0px 0px 10px;box-sizing:border-box;width:1200px;overflow: auto;display: flex;flex-wrap: wrap;justify-content: flex-start'>\n" +
                "\n" +
                "\n" +           name +
                "                </div>\n" +
                "            </div>",
        })
        layer.close(index);
    }
    //选择等级时 ajax
    function getMemberAjax(memberLevel,id,peopleType){
        $.ajax({
            url: '/admin/notice/look_member?people_type='+peopleType+'&member_level='+memberLevel+'&notice_id='+id,
            type: 'post',
            dataType: 'json',
            data: '',
            success: function (data) {
                var str = data.str;
                if (data.status == true) {
                    selectMemberType(str);

                }else{
                    layer.msg(data.msg,{icon:5,time:1000})
                }
            },
            error: function () {
                layer.msg("失败");
            }
        });
        return false
    }
</script>

</body>
</html>